package com.hx.yupao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hx.yupao.model.domain.Team;
import com.hx.yupao.model.domain.User;
import com.hx.yupao.model.domain.UserTeam;
import com.hx.yupao.mapper.UserTeamMapper;
import com.hx.yupao.model.vo.TeamUserVO;
import com.hx.yupao.service.UserTeamService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Lenovo
 * @description 针对表【user_team(用户队伍关系)】的数据库操作Service实现
 * @createDate 2025-10-02 16:00:08
 */
@Service
public class UserTeamServiceImpl extends ServiceImpl<UserTeamMapper, UserTeam>
        implements UserTeamService {
    @Resource
    private UserTeamMapper userTeamMapper;

    @Override
    public List<TeamUserVO> searchJoinTeams(User loginUser) {
        long loginUserId = loginUser.getId();
        List<Team> teamsByUserId = userTeamMapper.getTeamsByUserId(loginUserId);
        List<TeamUserVO> teamUserVOList = teamsByUserId.stream()
                .map(team -> {
                    TeamUserVO teamUserVO = new TeamUserVO();
                    BeanUtils.copyProperties(team, teamUserVO);
                    return teamUserVO;
                })
                .collect(Collectors.toList());
        return teamUserVOList;
    }
}




